
from appium import webdriver

from ui_framework.page.basepage import BasePage
from ui_framework.page.get_app_datas import GetAppDatas
from ui_framework.page.main_page import MainPage


class App(BasePage):
    def __init__(self,path):
        datas = GetAppDatas(path)
        desired_caps = datas.get_desired_caps()
        ip = datas.get_ip()
        port = datas.get_port()
        # 初始化driver
        self.driver = webdriver.Remote(f"http://{ip}:{port}/wd/hub", desired_caps)
        self.driver.implicitly_wait(10)

    def restart_app(self):
        self.driver.close_app()
        self.driver.launch_app()

    def close_app(self):
        self.driver.close_app()

    def goto_main_package(self):
        return MainPage(self.driver)